#!/bin/sh
# 初始化Server
projecr=test
URL=https://gitee.com/CZXyee/experimental-process
Branch=test

echo ""
echo "Initialization start..."
echo ""


# 初始化仓库
git init ${projecr}
cd ${projecr}
git remote add origin ${URL}
git config core.sparsecheckout true
echo "/*" >> .git/info/sparse-checkout
echo "!client/*" >> .git/info/sparse-checkout
echo "!*.md" >> .git/info/sparse-checkout
echo "!*.bat" >> .git/info/sparse-checkout
git fetch origin ${Branch}
git checkout ${Branch}


# 初始化路径
mv tmp/dist/* server/public/
rm sh/initServer.sh
mv sh/* ../
rm -r tmp
rm -r sh


# 初始化服务器
cd server
npm install


cd ..
cd ..
# 写入启动器
echo "cd ${projecr}" >> start.sh
echo "cd server" >> start.sh
echo "nohup node app.js &" >> start.sh

# 写入更新器
echo "echo" >> autoSyn.sh
echo "echo 'Synchronization start...'" >> autoSyn.sh
echo "echo" >> autoSyn.sh

echo "cd ${projecr}" >> autoSyn.sh
echo "git pull origin ${Branch}" >> autoSyn.sh
echo "git checkout ${Branch}" >> autoSyn.sh

echo "echo" >> autoSyn.sh
echo "echo 'Synchronization complete!'" >> autoSyn.sh
echo "echo" >> autoSyn.sh


echo ""
echo "Initialization complete"
echo "OVER!"
echo ""